<?php
/*
	******************************************************************************************
	Post/View Photos - Use Case 6.1, 6.2:  by Brannen Sorem,  Last Updated 03/20/10 - 9:58am

	Functional Specification
	Photo_upload.php processes and posts a photo to the Flickr account.  The photos 
	are stored on Flickr.com and accessed using a JSON request from a Flickr URL tied to the 
	account.  Posting photos is done through the Flickr API and uses a PHP library to do so - 
	phpFlickr.
	
	Web Master Maintenance:
	******************************************************************************************
	

	******************************************************************************************
*/

// need phpFlickr to make API calls
include_once("include/plugins/phpFlickr/phpFlickr.php");

// get data from form POST
$title = $_POST['title'];
$description = $_POST['description'];
$tags = $_POST['name'];

if ($title != "") {
	// make sure photo meets specifications (jpeg/gif, <=10MB)
	if ((($_FILES["file"]["type"] == "image/gif")
		|| ($_FILES["file"]["type"] == "image/jpeg")
		|| ($_FILES["file"]["type"] == "image/pjpeg"))
	&& ($_FILES["file"]["size"] < 10000000)){
		if ($_FILES["file"]["error"] > 0){
			echo "Photo not uploaded.";
		}
		else {
			// authorize Flickr access
			$f = new phpFlickr('b363504a0315a8f09703761f6a3cd3be', 'b2725b3e1652883e');
			$f->setToken('72157623468280953-5e70a6c74667821a');
			// upload and wait for response
			$response = $f->sync_upload($_FILES['file']['tmp_name'], $title, $description, $tags, 1, 0, 0);
			// if success, says so!
			if ($response) {
			  echo "Photo uploaded!";
			} else {
			  echo "Photo not uploaded";
			}
		}
	}
	else {
		echo "Invalid file.  Photo must be a JPG or GIF and cannot exceed 10Mb in size.";
	}
} else {
	echo "File not uploaded.  You must enter a title.";
}
?>